package com.oa.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.oa.ServiceImp.UserServiceImp;
import com.oa.entity.User;


@Controller 
public class Login {
	
	/*@Autowired    
	private UserService userService;*/
		
	
	     /**
	      * 到达登陆页面 
	      * @return
	      */
	    @RequestMapping("/login.do")  
	    public String login(){ 
	       
	        return "login";  
	    } 
	    
	    
	    /**
	     * 登陆验证
	     * @return
	     */
	    @RequestMapping(value = "/index.do")
	    public void loginin(String username,String password,String rnd,HttpServletResponse response){
	    	PrintWriter printWriter = null;
	    	try {
	    		response.setContentType("application/json;charset=UTF-8");
				printWriter = response.getWriter();
				String hSql = "from User where user_id= '"+username+"' and password = '"+password+"'";
				List<User> list = new UserServiceImp().find(hSql);
				
				
		    	printWriter.write("{\"flag\":\"sucess\"}");
		    	printWriter.flush();
		    	printWriter.close();
	    	} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }
	    
	    
	    /**
	     * 主页面
	     * @return
	     */
	    @RequestMapping(value = "/main.do")
	    public String mainHtml(){
	    	
	    	
	    	return "main";
	    }
	    
	    
	    
	    /**
	     * 退出
	     * @return
	     */
	    @RequestMapping("/logout.do")
	    public String logout(){
	    	
	    	return "login";
	    }
	    
}
